package com.fyzk.activity.lottery.jc.football;

import com.fyzk.activity.lottery.jc.football.guoguan.JC_GuoGuanInfor;
import com.fyzk.activity.zhifu.SportsFootballPayActivity;
import com.fyzk.utils.LotteryIDUtils;

import java.util.List;

import static com.fyzk.activity.lottery.jc.football.guoguan.JC_GuoGuanDialog.result;

/**
 * 竞彩足球支付的activity
 */
public class JCZQ_SPF_ZhiFuActivity extends SportsFootballPayActivity {

    @Override
    protected void onResume() {
        super.onResume();
        lotteryId = LotteryIDUtils.JZSPFRSPF_LOTTERY_ID_INT;
        buyType.setText("竞彩足球-胜平负");
    }

    @Override
    protected void clear() {
        // TODO Auto-generated method stub
        super.clear();
        for (int i = 0; i < infos.size(); i++) {
            JCInfo info = infos.get(i);
            if (info.getOnclikNum() > 0) {
                info.setOnclikNum(0);
                info.btnHGPojo.get(info.VS_3).isSel = false;
                info.btnHGPojo.get(info.VS_1).isSel = false;
                info.btnHGPojo.get(info.VS_0).isSel = false;
                info.btnHGPojo.get(info.LETVS_0).isSel = false;
                info.btnHGPojo.get(info.LETVS_1).isSel = false;
                info.btnHGPojo.get(info.LETVS_3).isSel = false;
            }
        }
        adapter.setInfors(infos, isDanguan);
    }

    @Override
    protected void initAdapter() {
        adapter = new JCZQ_ZhiFuAdapter(this, isDanguan, infos, handler, this);
        listView.setAdapter(adapter);
    }

    int lotteryId_real = LotteryIDUtils.JZSPF_LOTTERY_ID_INT;

    /**
     * 获取投注内容
     *
     * @param infos
     */
    public String getContent(List<JCInfo> infos, boolean isDanguan) {
        List<String> chuans = JC_GuoGuanInfor.getChuanIds(result, isDanguan);
        String content = "";
        for (int i = 0; i < chuans.size(); i++) {
            boolean hasSPF = false;
            boolean hasRSPF = false;
            for (JCInfo info : infos) {
                String[] keys = {info.VS_3, info.VS_1, info.VS_0};
                for (int j = 0; j < keys.length; j++) {
                    if (info.btnHGPojo.get(keys[j]).isSel) {
                        hasSPF = true;
                    }
                }
                String[] keys_r = {info.LETVS_0, info.LETVS_1, info.LETVS_3};
                for (int j = 0; j < keys_r.length; j++) {
                    if (info.btnHGPojo.get(keys_r[j]).isSel) {
                        hasRSPF = true;
                    }
                }
            }
            lotteryId_real = LotteryIDUtils.JZSPF_LOTTERY_ID_INT;
            if (hasSPF && hasRSPF) {
                lotteryId_real = LotteryIDUtils.JZHH_LOTTERY_ID_INT;
            } else if (hasSPF) {
                lotteryId_real = LotteryIDUtils.JZSPF_LOTTERY_ID_INT;
            } else if (hasRSPF) {
                lotteryId_real = LotteryIDUtils.JZRFSPF_LOTTERY_ID_INT;
            }
            lotteryId = lotteryId_real;
            content += lotteryId_real + "" + wanFa + chuans.get(i) + "-";// 301012001-
            String n = "";
            String danCodes = "";
            for (int j = 0; j < infos.size(); j++) {
                JCInfo info = infos.get(j);
                String danChang = "";
                if (info.getOnclikNum() != 0) {
                    if (lotteryId_real == LotteryIDUtils.JZHH_LOTTERY_ID_INT) {
                        String spf = "";
                        String rspf = "";
                        if (info.btnHGPojo.get(info.VS_0).isSel) {
                            spf += "0,";
                        }
                        if (info.btnHGPojo.get(info.VS_1).isSel) {
                            spf += "1,";
                        }
                        if (info.btnHGPojo.get(info.VS_3).isSel) {
                            spf += "3,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_0).isSel) {
                            rspf += "0,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_1).isSel) {
                            rspf += "1,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_3).isSel) {
                            rspf += "3,";
                        }
                        if (!spf.equals("")) {
                            spf = spf.substring(0, spf.length() - 1);
                            spf = info.getMatchNum() + "*" + LotteryIDUtils.JZSPF_LOTTERY_ID_INT + "(" + spf + ")|";
                        }
                        if (!rspf.equals("")) {
                            rspf = rspf.substring(0, rspf.length() - 1);
                            rspf = info.getMatchNum() + "*" + LotteryIDUtils.JZRFSPF_LOTTERY_ID_INT + "(" + rspf
                                    + ")|";
                        }
                        result = spf + rspf;
                        if (!result.equals("")) {
                            result = result.substring(0, result.length() - 1);
                        }
                        danChang += result;
                    } else {
                        danChang = info.getMatchNum() + "(";
                        if (info.btnHGPojo.get(info.VS_0).isSel) {
                            danChang += "0,";
                        }
                        if (info.btnHGPojo.get(info.VS_1).isSel) {
                            danChang += "1,";
                        }
                        if (info.btnHGPojo.get(info.VS_3).isSel) {
                            danChang += "3,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_0).isSel) {
                            danChang += "0,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_1).isSel) {
                            danChang += "1,";
                        }
                        if (info.btnHGPojo.get(info.LETVS_3).isSel) {
                            danChang += "3,";
                        }
                        danChang = danChang.substring(0, danChang.length() - 1);
                        danChang += ")";
                    }
                }
                if (!danChang.equals("")) {
                    if (info.isDan()) {
                        danCodes += danChang + "|";
                    } else {
                        n += danChang + "|";
                    }
                }
            }
            if (!danCodes.equals("")) {
                danCodes = danCodes.substring(0, danCodes.length() - 1);
                danCodes += "#";
            }
            if (!n.equals("")) {
                n = n.substring(0, n.length() - 1);
                n += "^";
            }
            content += danCodes + n + "!";
        }
        if (!content.equals("")) {
            content = content.substring(0, content.length() - 1);
        }

        return content;
    }


    @Override
    protected int getMaxGuoGuan() {
        // TODO Auto-generated method stub
        return 8;
    }

    @Override
    public void open(JCInfo info) {

    }
}
